package park

import (
	"parking-lot-go-dingding/controller"
	"parking-lot-go-dingding/model"

	"github.com/gin-gonic/gin"
)

func Detail(c *gin.Context) {

	requestStruct := struct {
		Id int `json:"id"`
	}{}

	//接收加密串
	if err := c.ShouldBindJSON(&requestStruct); err != nil {
		controller.Fail(c, "json接收失败"+err.Error())
		return
	}

	var parkingLotStruct model.ParkingLotStruct
	parkFind, err := parkingLotStruct.First(requestStruct.Id)
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	parkType := "未知"
	switch parkFind.PType {
	case 1:
		parkType = "路内"
	case 2:
		parkType = "路外"
	}

	parkReturn := map[string]interface{}{
		"id":             parkFind.Id,
		"much_id":        parkFind.MuchId,
		"park_code":      parkFind.ParkCode,
		"name":           parkFind.Name,
		"address":        parkFind.Address,
		"parking_number": parkFind.ParkingNumber,
		"stop_type":      parkFind.StopType,
		"longitude":      parkFind.Longitude,
		"latitude":       parkFind.Latitude,
		"state":          parkFind.State,
		"sort":           parkFind.Sort,
		"clicks":         parkFind.Clicks,
		"region_code":    parkFind.RegionCode,
		"region_name":    parkFind.RegionName,
		"park_city":      parkFind.ParkCity,
		"p_type":         parkType,
		"m_time":         parkFind.MTime,
		"free_minutes":   parkFind.FreeMinutes,
	}

	controller.Success(c, parkReturn)

}
